package com.lu.statistics.loader;

import com.lu.statistics.entity.SysConfig;
import com.lu.statistics.mapper.SysConfigMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class DataLoader {
    @Autowired
    private SysConfigMapper configMapper;
    private static Map<String, String> configCache = new ConcurrentHashMap<>();

    @PostConstruct
    public void init() {
        List<SysConfig> configList = configMapper.queryConfigList();
        if (configList !=null && configList.size()>0){
            for (SysConfig config:configList){
                configCache.put(config.getVariable(), config.getValue());
            }
        }
    }

    public static String getConfigValue(String key) {
        return configCache.get(key);
    }
}
